package com.hqyj.springtest.mapper.controller;

import java.util.HashMap;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.hqyj.springtest.pojo.School;
import com.hqyj.springtest.service.SchoolService;

//@Controller
public class SchoolController {
	@Autowired
	SchoolService ss ;
	//SchoolService ss = new SchoolService(); //�Լ��������� spring ��ܲ�������Զ�װ��
	                                        // SchoolService�У�ϣ���Զ�װ��SchoolMapper
	
	// -- spring mvc (ͨ��controller�����뵽jspҳ�棬 controller�������ݵĴ��� Ȼ�����ݣ� ת����jspҳ�棬 
	// jspҳ�棬������ʾ���ݡ�jstl+el���ʽ�� --- ajax�ķ�ʽ�������ݴ��䵽htmlҳ�棬Ȼ����js�ķ�ʽ����ʾ��ҳ���ϣ�ǰ��˷��뿪����)
	
	@RequestMapping("query.do")
	public String query(ModelMap map) {
		map.put("schools", ss.getAllSchool());
		return "index"; // ת��index.jspҳ��
	}
	
	@RequestMapping("query1.do")
	@ResponseBody // query1.do���󣬲���ת����index.jsp�� ����ֱ�ӷ����ַ���"index"
	public int query1(ModelMap map) {
		map.put("schools", ss.getAllSchool());
		// return "index"; -- ����ֵ����һ���ַ���
		//return  "{name:\"alice\"}"; //-- ����ֵ��һ��ƴ��Ϊjson��ʽ���ַ��� 
		return 10;
	}
	
	@RequestMapping("query2.do")
	@ResponseBody // query1.do���󣬲���ת����index.jsp�� ����ֱ�ӷ����ַ���"index"
	public List<School> query2() {
		// -- ���list�� ����ת��Ϊһ�����飬 ���������������json����
		// -- ��ѯ�Ľ��Ϊһ��List����
		List<School> list = ss.getAllSchool(); // school- {scCode:1001, scName:��ͨ��ѧ�� scBirth: .... , sc.....}
		return list;   
	}
	
	@RequestMapping("query3.do")
	@ResponseBody // query1.do���󣬲���ת����index.jsp�� ����ֱ�ӷ����ַ���"index"
	public School query3() {
		// -- ���list�� ����ת��Ϊһ�����飬 ���������������json����
		// -- ��ѯ�Ľ��Ϊһ��List����
		List<School> list = ss.getAllSchool(); // school- {scCode:1001, scName:��ͨ��ѧ�� scBirth: .... , sc.....}
		return list.get(0);   
	}
	
	@RequestMapping("query4.do")
	@ResponseBody // query1.do���󣬲���ת����index.jsp�� ����ֱ�ӷ����ַ���"index"
	public HashMap<String, Integer> query4() {
		HashMap<String, Integer> scores = new HashMap<String,Integer>();
		scores.put("alice", 88);
		scores.put("jack", 90);
		return scores;   
	}
	
	
}
